home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MPW_TOOL
/
TOOLS
/
TOOLS_WI
/
ICON_8
/
MEMMON_F
/
MMAIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-02
|
4KB
|
161 lines
/*
* mmain.c: code shared among memmon back ends.
*/
/* in this file only, define globals instead of just declaring */
#define Global
#include "memmon.h"
hidden novalue mmoptions Params((int argc, char *argv[]));
hidden novalue mmusage Params((noargs));
static int justcolors = 0; /* quit after setting colors? */
static int gcskip = 0; /* number of gc's to skip */
/*
* main program.
*/
novalue main(argc, argv)
int argc;
char *argv[];
{
progname = argv[0]; /* save program name for diagnostics */
devsetup(); /* init device-dependent params */
initcolors(); /* init color tables */
mmoptions(argc, argv); /* process command options */
devinit(); /* open and initialize device */
if (justcolors) { /* if just color setting wanted: */
setmap(Marked, C_Marked); /* load color map */
mquit(NormalExit); /* terminate */
}
if (strcmp(whenpause,"") != 0 && strcmp(whenpause,"n") != 0 && !batchmode) {
ttyi = fopen("/dev/tty", "r"); /* init tty input file */
ttyo = fopen("/dev/tty", "w"); /* init tty output file */
if (ttyi == NULL || ttyo == NULL) {
fprintf(stderr, "%s: can't open /dev/tty; will not pause\n", progname);
ttyi = ttyo = NULL;
}
}
skipgc(gcskip); /* skip the first n collections */
memmon(); /* run the memory monitor */
mquit(NormalExit); /* terminate */
}
/*
* mmoptions(argc, argv) - process command options.
*/
static novalue mmoptions(argc, argv)
int argc;
char *argv[];
{
int c;
extern char *optarg; /* getopt() */
extern int optind; /* getopt() */
/*
* set some defaults
*/
gclimit = -1; /* no limit on gc's */
pauselimit = -1; /* no limit on pauses */
whichregs = "sb"; /* regions */
if (batchmode)
whenpause = "fgacpd"; /* pause/print points */
else
whenpause = "fgacp"; /* pause/print points */
/*
* We should ideally keep the next two lines in sync!
* Unfortunately, there are too many options to include all in synopsis.
*/
#define MMUse "[-r {fsb}] [-p {fgacpdn}] [-bwhLMgqQS n] [-t title] [...] [file]"
while ((c = getopt(argc, argv, "r:p:b:w:h:L:M:g:q:Q:S:t:mc:C:")) != EOF)
switch (c) {
case 'r':
whichregs = optarg;
break;
case 'p':
whenpause = optarg;
break;
case 'b':
granularity = atoi(optarg);
break;
case 'w':
width = atoi(optarg);
break;
case 'h':
height = atoi(optarg);
break;
case 'L':
textrow = atoi(optarg);
break;
case 'M':
memrow = atoi(optarg);
break;
case 'g':
gcskip = atoi(optarg);
break;
case 'q':
gclimit = atoi(optarg);
break;
case 'Q':
pauselimit = atoi(optarg);
break;
case 'S':
sfreq = atoi(optarg);
break;
case 't':
title = optarg;
break;
case 'm':
showmarking = 1;
break;
case 'c':
readcolors(optarg);
break;
case 'C':
justcolors = 1;
readcolors(optarg);
break;
default:
mmusage();
}
if (index(whenpause, 'g') || index(whenpause, 'a'))
showmarking = 1; /* show marking if going to pause */
if (optind + 1 < argc) /* if too many files named, quit */
mmusage();
if (optind < argc) { /* open input file, if specified */
ifile = fopen(argv[optind], "r");
if (!ifile)
pexit(argv[optind]);
if (!title)
title = argv[optind]; /* use file name as default title */
}
else /* else use standard input */
ifile = stdin;
}
/*
* mmusage() - diagnose bad memmon usage, and abort.
*/
static novalue mmusage()
{
fprintf(stderr, "usage: %s %s\n", progname, MMUse);
exit(ErrorExit);
}
/*
* mquit(exitcode) - terminate the run.
*/
novalue mquit(exitcode)
int exitcode;
{
devterm(); /* close down the graphics device */
exit(exitcode);
}